package org.lc.stk.model.user;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.annotations.Comment;
import org.lc.stk.model.baseInfo.Department;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

/**
 * 用户基类
 */
@Entity
@Table(name = "[user]")
@Inheritance(strategy = InheritanceType.JOINED)
@Comment("用户")
public abstract class User {

    public enum UserState {
        ENABLED(1),
        DISABLED(0);
        private final int value;
        UserState(int value) {
            this.value = value;
        }
        public int getValue() {
            return value;
        }
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(unique = true)
    @Comment("登录账号")
    private String username;

    @Column
    @Comment("密码")
    private String password;

    @Column
    @Comment("姓名")
    private String name;

    @Column
    @Comment("邮箱")
    private String email;

    @Column
    @Comment("状态(0:禁用 1:启用)")
    private Integer state = 1;

    @Column
    @Comment("是否已删除")
    private Boolean deleted = false;

    @ManyToOne
    @Comment("部门")
    private Department department;

    @OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
    private Set<UserRole> roles = new HashSet<>();

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getState() {
        return state;
    }

    public void setState(UserState state) {
        this.state = state.getValue();
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public Set<UserRole> getRoles() {
        return roles;
    }

    public void setRoles(Set<UserRole> roles) {
        this.roles = roles;
    }
}
